package xcmg.device.dao.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import xcmg.device.dao.entity.sale.SaleIntentionDetailDO;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Mapper
public interface SaleIntentionDetailMapper {


    List<SaleIntentionDetailDO> list(@Param("saleIntentionId") String saleIntentionId);

    List<SaleIntentionDetailDO> getBySaleNo(@Param("saleNo") String saleNo);

    List<SaleIntentionDetailDO> listWithRownum(@Param("saleIntentionId") String saleIntentionId);

    List<SaleIntentionDetailDO> listForDeliveryNote(@Param("saleIntentionId") String saleIntentionId);

    List<SaleIntentionDetailDO> listNoPrice(@Param("saleIntentionId") String saleIntentionId);

    int  updateDeliveryNoteNum(@Param("saleNo") String saleNo,@Param("materialsNo") String materialsNo,@Param("informedAmount") Integer informedAmount);

    SaleIntentionDetailDO findBySaleIntentionIdAndMaterialsNo(@Param("saleIntentionId") String saleIntentionId, @Param("materialsNo") String materialsNo);

    int insert(SaleIntentionDetailDO record);

    int remove(@Param("saleIntentionId") String saleIntentionId);

    int batchInsert(List<SaleIntentionDetailDO> list);

//    SaleIntentionDetailDO selectByPrimaryKey(String id);

    int update(SaleIntentionDetailDO record);

    int updateByPrimaryKey(SaleIntentionDetailDO record);

    int updateInformAmount(SaleIntentionDetailDO record);

    SaleIntentionDetailDO selectByNo(@Param("saleNo")String saleNo,@Param("materialsNo")String materialsNo);

    /**
     * 修改退货状态
     * @param saleNo  String 销售单号
     * @param status Integer 退货状态（0未退货，1退货中，2退货完成）
     * @return int
     */
    int updateReturnStatus(@Param("saleNo")String saleNo,@Param("status")Integer status);

    BigDecimal findOccupyNum(@Param("materialsNo")String materialsNo, @Param("orgId")String orgId);

    BigDecimal unSendAmount(@Param("saleId")String saleId);

    BigDecimal sendAmount(@Param("saleId")String saleId);

    int updateByReturnApply(@Param("applyQty")BigDecimal applyQty,@Param("saleNo")String saleNo,@Param("materialsNo")String materialsNo,@Param("isReturn")Integer isReturn);
    

    /**
     * 退货申请审核拒绝，变更销售单零件状态以及零件的退货数量
     * @param applyQty Integer 退货申请数量
     * @param saleNo String 销售达的销售单号
     * @param materialsNo String 零件编号
     * @param auditStatus Integer 审核状态
     * @return int
     */
    int updateByAutidFail(@Param("applyQty")BigDecimal applyQty, @Param("saleNo")String saleNo, @Param("materialsNo")String materialsNo, @Param("auditStatus")Integer auditStatus);

    int itemRemove(@Param("detailId")String detailId);

    int countBySaleIntentionId(@Param("saleIntentionId")String saleIntentionId);

    Date getDeliveryDate(@Param("materialsNo")String materialsNo, @Param("billId")String billId);

    void updateInventoryOutStatus(@Param("saleNo") String saleNo,@Param("inventoryOutStatus") String inventoryOutStatus);
}